﻿<ResourceDictionary xmlns="http://schemas.microsoft.com/winfx/2006/xaml/presentation"
                    xmlns:x="http://schemas.microsoft.com/winfx/2006/xaml" 
                    xmlns:local="clr-namespace:AutomationMLMapper.Controls"
                    xmlns:MarkupExtensions="clr-namespace:AutomationMLMapper.Controls.MarkupExtensions"
                    xmlns:ConvertersAndTemplateSelectors="clr-namespace:AutomationMLMapper.Controls.ConvertersAndTemplateSelectors">

    <ResourceDictionary.MergedDictionaries>
        <ResourceDictionary Source="/AutomationMLMapper;component/StyleResources/ListStyle.xaml"/>
    </ResourceDictionary.MergedDictionaries>

    <DataTemplate x:Key="ExistStateTemplate">
        <Ellipse x:Name="StateIcon" Margin="2,0,5,0" Height="8" Width="8" HorizontalAlignment="Right"  Fill="LimeGreen" StrokeThickness="0.4">
            <Ellipse.Stroke>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </Ellipse.Stroke>
        </Ellipse>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Exist, UpdateSourceTrigger=PropertyChanged}" Value="True">
                <DataTrigger.Setters>
                    <Setter Property="Fill" Value="LimeGreen" TargetName="StateIcon" />
                </DataTrigger.Setters>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=Exist, UpdateSourceTrigger=PropertyChanged}" Value="False">
                <DataTrigger.Setters>
                    <Setter Property="Fill" Value="Red" TargetName="StateIcon" />
                </DataTrigger.Setters>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>

    <DataTemplate x:Key="DiffStateTemplate">
        <Ellipse x:Name="StateIcon" Margin="2,0,5,0" Height="8" Width="8" HorizontalAlignment="Right"  Fill="LimeGreen" StrokeThickness="0.4">
            <Ellipse.Stroke>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </Ellipse.Stroke>
        </Ellipse>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=isEqual, UpdateSourceTrigger=PropertyChanged}" Value="True">
                <DataTrigger.Setters>
                    <Setter Property="Fill" Value="LimeGreen" TargetName="StateIcon" />
                </DataTrigger.Setters>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=isEqual, UpdateSourceTrigger=PropertyChanged}" Value="False">
                <DataTrigger.Setters>
                    <Setter Property="Fill" Value="Red" TargetName="StateIcon" />
                </DataTrigger.Setters>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    
    <DataTemplate x:Key="ChangeStateTemplate">        
        <Ellipse x:Name="StateIcon" Margin="2,0,5,0" Height="8" Width="8" HorizontalAlignment="Right"  Fill="LimeGreen" StrokeThickness="0.4">
            <Ellipse.Stroke>
                <LinearGradientBrush EndPoint="0.5,1" StartPoint="0.5,0">
                    <GradientStop Color="Black" Offset="0"/>
                    <GradientStop Color="White" Offset="1"/>
                </LinearGradientBrush>
            </Ellipse.Stroke>
        </Ellipse>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext.IsDirty, UpdateSourceTrigger=PropertyChanged}" Value="True">
                <DataTrigger.Setters>
                    <Setter Property="Fill" Value="Red" TargetName="StateIcon" />
                </DataTrigger.Setters>
            </DataTrigger>
            <DataTrigger Binding="{Binding RelativeSource={RelativeSource TemplatedParent}, Path=DataContext.IsDirty, UpdateSourceTrigger=PropertyChanged}" Value="False">
                <DataTrigger.Setters>
                    <Setter Property="Fill" Value="LimeGreen" TargetName="StateIcon" />
                </DataTrigger.Setters>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    
    <DataTemplate x:Key="NameInputTemplate">
        <AdornerDecorator>
            <TextBox VerticalAlignment="Top"  Style="{StaticResource ValidationTextBox}"  Text="{Binding Path=Name, UpdateSourceTrigger=LostFocus,
                     ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Margin="5,2,2,2" ></TextBox>
        </AdornerDecorator>
    </DataTemplate>

    <DataTemplate x:Key="NameOutputTemplateWithChangeToolTip">
        <TextBlock VerticalAlignment="Top" Text="{Binding Name}">            
            <TextBlock.ToolTip>
                <TextBlock x:Name="ChangeResult" Height="Auto" Text="{Binding ComparerResultString, Mode=OneTime}"
                 HorizontalAlignment="Left" VerticalAlignment="Top"
                 TextWrapping="Wrap">                    
                </TextBlock>
            </TextBlock.ToolTip>
        </TextBlock>
    </DataTemplate>
    
    <DataTemplate x:Key="NameOutputTemplate">
        <TextBlock VerticalAlignment="Top" Text="{Binding Name}"></TextBlock>
    </DataTemplate>

    <Style x:Key="ToggleButtonStyle" TargetType="{x:Type ToggleButton}">
        <Setter Property="Template">
            <Setter.Value>
                <ControlTemplate TargetType="{x:Type ToggleButton}">
                    <Grid>
                        <Image x:Name="ButtonImage" Source="{MarkupExtensions:ImageResolution Source=SRC_red.ico,Size=24}"/>
                        <ContentPresenter HorizontalAlignment="{TemplateBinding HorizontalContentAlignment}" RecognizesAccessKey="True" SnapsToDevicePixels="{TemplateBinding SnapsToDevicePixels}" VerticalAlignment="{TemplateBinding VerticalContentAlignment}"/>
                    </Grid>
                    
                    <ControlTemplate.Triggers>
                            <DataTrigger Binding="{Binding HasSupportedRoles}" Value="true">
                            <Setter TargetName="ButtonImage" Property="Source" Value="{MarkupExtensions:ImageResolution Source=SRC_green.ico, Size=24}"/>
                            </DataTrigger>
                        <DataTrigger Binding="{Binding HasSupportedRoles}" Value="false">
                            <Setter TargetName="ButtonImage" Property="Source" Value="{MarkupExtensions:ImageResolution Source=SRC_red.ico,Size=24}"/>
                        </DataTrigger>
                    </ControlTemplate.Triggers>
                </ControlTemplate>
            </Setter.Value>
        </Setter>
    </Style>
        
    <DataTemplate x:Key="SystemUnitClassTemplate">
        <Border Background="White" BorderBrush="LightGray" BorderThickness="1,1,1,1">
            <Grid>
                <Grid.ColumnDefinitions>
                    <ColumnDefinition Width="*"></ColumnDefinition>
                    <ColumnDefinition Width="Auto" SharedSizeGroup="col2"></ColumnDefinition>
                </Grid.ColumnDefinitions>
                <AdornerDecorator Grid.Column="0">
                    <TextBox VerticalAlignment="Top"  Style="{StaticResource ValidationTextBox}"  Text="{Binding Path=Name, UpdateSourceTrigger=LostFocus,
                         ValidatesOnDataErrors=true, NotifyOnValidationError=true}" BorderThickness="0,0,1,0" ></TextBox>
                </AdornerDecorator>
                <ToggleButton ToolTip="Supported Roles" x:Name="SRCButton" Grid.Column="1" Style="{StaticResource ToggleButtonStyle}" 
                              HorizontalAlignment="Right" VerticalAlignment="Center" Margin="2,0" Command="{Binding ShowSupportedRoles}"/>
            </Grid>
        </Border>
    </DataTemplate>
    
    <DataTemplate x:Key="ExportInternalElementTemplate">
        <TextBlock x:Name="NameText" VerticalAlignment="Top" Margin="5" Background="LightSalmon" Text="{Binding Name}"></TextBlock>
        <DataTemplate.Triggers>
            <DataTrigger Binding="{Binding IsImported}" Value="true">
                <Setter TargetName="NameText" Property="Background" Value="LightGreen"/>
            </DataTrigger>
        </DataTemplate.Triggers>
    </DataTemplate>
    
    <DataTemplate x:Key="ImportInternalElementTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="*"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col2"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <AdornerDecorator Grid.Column="0">
                <TextBlock  Style="{StaticResource ValidationTextBlock}"  
                            Text="{Binding Path=Name, UpdateSourceTrigger=LostFocus, 
				            ValidatesOnDataErrors=true, NotifyOnValidationError=true}" MinWidth="200" Margin="5,2,2,2"></TextBlock>
            </AdornerDecorator>
            <CheckBox HorizontalAlignment="Right" VerticalAlignment="Center" 
                      Grid.Column="1" IsChecked="{Binding Path=MapToClass, Mode=TwoWay}"></CheckBox>
        </Grid>
    </DataTemplate>
    
    <DataTemplate x:Key="MappingTypeOutputTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="col1"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col2"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Margin="0,2,5,2" Grid.Column="0">
                <Run FontWeight="DemiBold" Text="ClassAttribute: "></Run>
                <Run Text="{Binding ClassAttributeName}"></Run>
            </TextBlock>
            <TextBlock Grid.Column="1">
                <Run FontWeight="DemiBold" Text="RoleAttribute: "></Run>
                <Run Text="{Binding RoleAttributeName}"></Run>
            </TextBlock>
        </Grid>
    </DataTemplate>
    
    <DataTemplate x:Key="MappingTypeInputTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="col1"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col2"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Margin="0,2,5,2" Grid.Column="0">
                <Run FontWeight="DemiBold" Text="ClassAttribute: "></Run>
                <Run Text="{Binding ClassAttributeName}"></Run>
            </TextBlock>
            <TextBlock Grid.Column="1">
                <Run FontWeight="DemiBold" Text="RoleAttribute: "></Run>
                <Run Text="{Binding RoleAttributeName}"></Run>
            </TextBlock>
        </Grid>
    </DataTemplate>
    
    <DataTemplate x:Key="AttributeOutputTemplate">  
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="col1"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col2"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Margin="0,0,5,0" Grid.Column="0">
                <Run FontWeight="DemiBold" Text="Name: "></Run>
                <Run Text="{Binding Name}"></Run>
            </TextBlock>
            <TextBlock Grid.Column="1">
                <Run FontWeight="DemiBold" Text="Unit: "></Run>
                <Run Text="{Binding Unit}"></Run>
            </TextBlock>
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="AttributeInputTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col2"></ColumnDefinition>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col4"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            
            <Label Grid.Column="0" FontWeight="DemiBold" Content="Name: "/>
            <AdornerDecorator Grid.Column="1">
                <TextBox MinWidth="150" Style="{StaticResource ValidationTextBox}"  Text="{Binding Path=Name, UpdateSourceTrigger=LostFocus,
                     ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Margin="5,0,0,0" ></TextBox>
            </AdornerDecorator>
            <Label Grid.Column="2" FontWeight="DemiBold"  Content="Unit: "/>
            <TextBox Grid.Column="3" MinWidth="80" Style="{StaticResource ValidationTextBox}"  Text="{Binding Path=Unit, UpdateSourceTrigger=LostFocus}" Margin="5,0,0,0" ></TextBox>
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="PropertySetInputTemplate">
        <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition Width="Auto"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col2"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col3"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col4"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <Label Grid.Column="0" FontWeight="DemiBold" Content="Name: "/>
            <AdornerDecorator Grid.Column="1">
                <TextBox MinWidth="150" Style="{StaticResource ValidationTextBox}"  Text="{Binding Path=Name, UpdateSourceTrigger=LostFocus,
                     ValidatesOnDataErrors=true, NotifyOnValidationError=true}" Margin="5,0,0,0" ></TextBox>
            </AdornerDecorator>
            <local:CAEXCollectionView AddToolTipDescription="To add a Mapping, please select an attribute from the SystemUnitClass and a corresponding attribute from the PropertySet"
                                      DeleteToolTipDescription="Delete the current Mapping between Class-Attribute and PropertySet-Attribute"
                                      DataContext="{Binding MappingObjectCollection}" Grid.Column="2"></local:CAEXCollectionView>
            <local:CAEXCollectionView AllowAdd="False" AllowDelete="False" AllowEditElement="False" DataContext="{Binding AttributesCollection}" Grid.Column="3"></local:CAEXCollectionView>
        </Grid>
    </DataTemplate>

    <DataTemplate x:Key="PropertySetOutputTemplate">
         <Grid>
            <Grid.ColumnDefinitions>
                <ColumnDefinition SharedSizeGroup="col1"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col2"></ColumnDefinition>
                <ColumnDefinition SharedSizeGroup="col3"></ColumnDefinition>
            </Grid.ColumnDefinitions>
            <TextBlock Margin="0,0,5,0" Grid.Column="0">
                <Run FontWeight="DemiBold" Text="Name: "></Run>
                <Run Text="{Binding Name}"></Run>
            </TextBlock>
            <local:CAEXCollectionView AllowAdd="False" AllowDelete="False" AllowEditElement="False" DataContext="{Binding MappingObjectCollection}" Grid.Column="1"></local:CAEXCollectionView>
            <local:CAEXCollectionView AllowAdd="False" AllowDelete="False" AllowEditElement="False" DataContext="{Binding AttributesCollection}" Grid.Column="2"></local:CAEXCollectionView>
        </Grid>
    </DataTemplate>
    
    <ConvertersAndTemplateSelectors:AutomationMLObjectRepresentationTemplateSelector x:Key="EditableAutomationMLTemplateSelector"
        SupportedRoleClassTemplate="{StaticResource NameInputTemplate}"
        RequiredRoleClassTemplate="{StaticResource NameInputTemplate}" 
        ImportInternalElementTemplate="{StaticResource ImportInternalElementTemplate}"
        ExportInternalElementTemplate="{StaticResource ExportInternalElementTemplate}" 
        RoleClassTemplate ="{StaticResource NameInputTemplate}"
        RoleClassLibTemplate ="{StaticResource NameInputTemplate}"
        SytemUnitClassTemplate ="{StaticResource SystemUnitClassTemplate}"
        AttributeTemplate ="{StaticResource AttributeInputTemplate}"
        MappingTypeTemplate ="{StaticResource MappingTypeInputTemplate}"
        PropertySetTemplate ="{StaticResource PropertySetInputTemplate}"
        InternalElementTemplate="{StaticResource NameInputTemplate}"/>

    <ConvertersAndTemplateSelectors:AutomationMLObjectRepresentationTemplateSelector x:Key="ReadOnlyAutomationMLTemplateSelector"
        SupportedRoleClassTemplate="{StaticResource NameOutputTemplate}"
        RequiredRoleClassTemplate="{StaticResource NameOutputTemplate}" 
        RoleClassTemplate ="{StaticResource NameOutputTemplate}"
        RoleClassLibTemplate ="{StaticResource NameOutputTemplate}"
        SytemUnitClassTemplate ="{StaticResource NameOutputTemplate}"                                                            
        ImportInternalElementTemplate="{StaticResource ImportInternalElementTemplate}"
        ExportInternalElementTemplate="{StaticResource ExportInternalElementTemplate}"        
        AttributeTemplate ="{StaticResource AttributeOutputTemplate}" 
        MappingTypeTemplate ="{StaticResource MappingTypeOutputTemplate}"                                                           
        PropertySetTemplate ="{StaticResource PropertySetOutputTemplate}"
        InternalElementTemplate="{StaticResource NameOutputTemplate}"/>

</ResourceDictionary>